package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品数据
     */
    @AutoFill(value = OperationType.INSERT)
    void saveDish(Dish dish);


    /**
     *
     * @param id 根据ID查询菜品
     * @return 菜品数据
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    void delete(List<Long> ids);

    @AutoFill(value = OperationType.UPDATE)
    // 只有参数是实体对象，且实现了自动填充的方法时，才能使用AutoFill注解
    void startOrStop(Dish dish);

    @AutoFill(value = OperationType.UPDATE)
    void updateDish(Dish dish);

    @Select("select * from dish where category_id = #{id}")
    List<DishVO> getByCategoryId(Long id);

    // 根据 category_id 和 status 查询菜品数据，并且查询口味数据
    // 根据菜品查询对应的口味数据

    List<DishVO> listWithFlavor(Dish dish);

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{id}")
    List<Dish> getBySetmealId(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
